package date0703am;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;

/**
 * 通过 数据库连接 可以获得 数据库元数据 ( Database Meta Data )
 */
public class JdbcTest13 {

	public static void main(String[] args) throws Exception {
		
		String driver = "com.mysql.cj.jdbc.Driver"  ;
		String url = "jdbc:mysql://localhost:3306/ecut?serverTimezone=Asia/Shanghai&useSSL=false" ;
		String user = "ecuter" ;
		String password = "ecuter" ;
		
//		String driver =  "oracle.jdbc.driver.OracleDriver"  ;
//		String url = "jdbc:oracle:thin:@localhost:1521:ecut" ;
//		String user = "ecuter" ;
//		String password = "ecuter" ;
		
		// 1、加载驱动
		Class.forName( driver );
		
		// 2、获取连接
		Connection conn = DriverManager.getConnection(url, user, password);
		
		// 通过 连接 ( Connection ) 来获取 数据库元数据 ( DatabaseMetaData )
		DatabaseMetaData meta = conn.getMetaData();
		System.out.println( "数据库名称: " + meta.getDatabaseProductName() ) ;
		System.out.println( "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " );
		
		System.out.println( "数据库版本: " + meta.getDatabaseProductVersion() ) ;
		System.out.println( "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " );
		
		System.out.println( "数据库驱动名称: " + meta.getDriverName() ) ;
		System.out.println( "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " );
		
		System.out.println( "数据库驱动版本: " + meta.getDriverVersion() ) ;
		
		System.out.println( "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = " );
		
		// 判断此数据库驱动是否支持给定结果集类型 ( 在 java.sql.ResultSet 中定义 )
		boolean t = meta.supportsResultSetType( ResultSet.TYPE_SCROLL_INSENSITIVE ) ;
		System.out.println(  t );
		
		// 判断此 数据库驱动 是否支持与给定结果集类型结合在一起的给定并发性类型 (在 java.sql.ResultSet 中定义 )
		boolean c = meta.supportsResultSetConcurrency( ResultSet.TYPE_SCROLL_INSENSITIVE , ResultSet.CONCUR_UPDATABLE )  ;
		System.out.println( c );
		
		// 6、释放资源
		conn.close();

	}

}
